﻿ 
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;

namespace GRPCBase
{
    public static class gRPC
    {
        static readonly string __ServiceName = "gRPCBase.gRPC";

        static readonly Marshaller<global::GRPCBase.TaskRequest> __Marshaller_HelloRequest = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::GRPCBase.TaskRequest.Parser.ParseFrom);
        static readonly Marshaller<global::GRPCBase.TaskReply> __Marshaller_HelloReply = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::GRPCBase.TaskReply.Parser.ParseFrom);

        static readonly Method<global::GRPCBase.TaskRequest, global::GRPCBase.TaskReply> __Method_SayHello = new Method<global::GRPCBase.TaskRequest, global::GRPCBase.TaskReply>(
            MethodType.Unary,
            __ServiceName,
            "SayHello",
            __Marshaller_HelloRequest,
            __Marshaller_HelloReply);

        static readonly Method<global::GRPCBase.TaskRequest, global::GRPCBase.TaskReply> __Method_AddTask = new Method<global::GRPCBase.TaskRequest, global::GRPCBase.TaskReply>(
             MethodType.Unary,
             __ServiceName,
             "AddTask",
             __Marshaller_HelloRequest,
             __Marshaller_HelloReply);

        static readonly Method<global::GRPCBase.TaskRequest, global::GRPCBase.TaskReply> __Method_GetTaskNoEndCount = new Method<global::GRPCBase.TaskRequest, global::GRPCBase.TaskReply>(
         MethodType.Unary,
         __ServiceName,
         "GetTaskNoEndCount",
         __Marshaller_HelloRequest,
         __Marshaller_HelloReply);

        static readonly Method<global::GRPCBase.TaskRequest, global::GRPCBase.TaskReply> __Method_GetTaskNoAllotCount = new Method<global::GRPCBase.TaskRequest, global::GRPCBase.TaskReply>(
         MethodType.Unary,
         __ServiceName,
         "GetTaskNoAllotCount",
         __Marshaller_HelloRequest,
         __Marshaller_HelloReply);

        /// <summary>Service descriptor</summary>
        public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
        {
            get { return global::GRPCBase.TaskReflection.Descriptor.Services[0]; }
        }

        /// <summary>Base class for server-side implementations of gRPC</summary>
        public abstract class gRPCBase
        {
            public virtual global::System.Threading.Tasks.Task<global::GRPCBase.TaskReply> SayHello(global::GRPCBase.TaskRequest request, ServerCallContext context)
            {
                throw new RpcException(new Status(StatusCode.Unimplemented, ""));
            }

            public virtual global::System.Threading.Tasks.Task<global::GRPCBase.TaskReply> AddTask(global::GRPCBase.TaskRequest request, ServerCallContext context)
            {
                throw new RpcException(new Status(StatusCode.Unimplemented, ""));
            }
            public virtual global::System.Threading.Tasks.Task<global::GRPCBase.TaskReply> GetTaskNoEndCount(global::GRPCBase.TaskRequest request, ServerCallContext context)
            {
                throw new RpcException(new Status(StatusCode.Unimplemented, ""));
            }
            public virtual global::System.Threading.Tasks.Task<global::GRPCBase.TaskReply> GetTaskNoAllotCount(global::GRPCBase.TaskRequest request, ServerCallContext context)
            {
                throw new RpcException(new Status(StatusCode.Unimplemented, ""));
            }

        }

        /// <summary>Client for gRPC</summary>
        public class gRPCClient : ClientBase<gRPCClient>
        {
            /// <summary>Creates a new client for gRPC</summary>
            /// <param name="channel">The channel to use to make remote calls.</param>
            public gRPCClient(Channel channel) : base(channel)
            {
            }
            /// <summary>Creates a new client for gRPC that uses a custom <c>CallInvoker</c>.</summary>
            /// <param name="callInvoker">The callInvoker to use to make remote calls.</param>
            public gRPCClient(CallInvoker callInvoker) : base(callInvoker)
            {
            }
            /// <summary>Protected parameterless constructor to allow creation of test doubles.</summary>
            protected gRPCClient() : base()
            {
            }
            /// <summary>Protected constructor to allow creation of configured clients.</summary>
            /// <param name="configuration">The client configuration.</param>
            protected gRPCClient(ClientBaseConfiguration configuration) : base(configuration)
            {
            }

            public virtual global::GRPCBase.TaskReply SayHello(global::GRPCBase.TaskRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
            {
                return SayHello(request, new CallOptions(headers, deadline, cancellationToken));
            }
            public virtual global::GRPCBase.TaskReply AddTask(global::GRPCBase.TaskRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
            {
                return AddTask(request, new CallOptions(headers, deadline, cancellationToken));
            }
            public virtual global::GRPCBase.TaskReply GetTaskNoEndCount(global::GRPCBase.TaskRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
            {
                return GetTaskNoEndCount(request, new CallOptions(headers, deadline, cancellationToken));
            }
            public virtual global::GRPCBase.TaskReply GetTaskNoAllotCount(global::GRPCBase.TaskRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
            {
                return GetTaskNoAllotCount(request, new CallOptions(headers, deadline, cancellationToken));
            }


            public virtual global::GRPCBase.TaskReply SayHello(global::GRPCBase.TaskRequest request, CallOptions options)
            {
                return CallInvoker.BlockingUnaryCall(__Method_SayHello, null, options, request);
            }
            public virtual global::GRPCBase.TaskReply AddTask(global::GRPCBase.TaskRequest request, CallOptions options)
            {
                return CallInvoker.BlockingUnaryCall(__Method_AddTask, null, options, request);
            }
            public virtual global::GRPCBase.TaskReply GetTaskNoEndCount(global::GRPCBase.TaskRequest request, CallOptions options)
            {
                return CallInvoker.BlockingUnaryCall(__Method_GetTaskNoEndCount, null, options, request);
            }

            public virtual global::GRPCBase.TaskReply GetTaskNoAllotCount(global::GRPCBase.TaskRequest request, CallOptions options)
            {
                return CallInvoker.BlockingUnaryCall(__Method_GetTaskNoAllotCount, null, options, request);
            }

            public virtual AsyncUnaryCall<global::GRPCBase.TaskReply> SayHelloAsync(global::GRPCBase.TaskRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
            {
                return SayHelloAsync(request, new CallOptions(headers, deadline, cancellationToken));
            }
            public virtual AsyncUnaryCall<global::GRPCBase.TaskReply> SayHelloAsync(global::GRPCBase.TaskRequest request, CallOptions options)
            {
                return CallInvoker.AsyncUnaryCall(__Method_SayHello, null, options, request);
            }
            protected override gRPCClient NewInstance(ClientBaseConfiguration configuration)
            {
                return new gRPCClient(configuration);
            }
        }

        /// <summary>Creates service definition that can be registered with a server</summary>
        public static ServerServiceDefinition BindService(gRPCBase serviceImpl)
        {
            return ServerServiceDefinition.CreateBuilder()
                .AddMethod(__Method_SayHello, serviceImpl.SayHello).Build();
        }

    }

}